export default {
    state: {
        listCity: []
    },
    mutations: {
        // mutations里面的方法只做数据操作，不接受任何变量
        // 添加最近点击的城市
        add(state, itemNew) {
            state.listCity = JSON.parse(localStorage.getItem('list'))
            if ( (state.listCity && state.listCity.length) === 3) {
                    state.listCity.filter(item =>{
                            return item !== itemNew
                        })
                        state.listCity && state.listCity.unshift(itemNew)
            } else {
                state.listCity && state.listCity.unshift(itemNew)
            }
            // 去重处理
            var set = new Set();
            state.listCity && state.listCity.forEach(item => {
                set.add(item)
            })
            state.listCity = [...set]
            // 存localStorage
            localStorage.setItem("list",JSON.stringify(state.listCity))
        }
    },
    actions: {

    }
}